#pragma once
#include <iostream>
#include <string>
#include <vector>
#include <unistd.h>
using namespace std;
class Cut
{
public:
    Cut(std::string &event)
        : _require(event)
    {
        Cutrow();
        Cutcow(event);
    }

private:
    void Cutrow()
    {
        while (!_require.empty())
        {
            int pos = _require.find('\n');
            if (pos == std::string::npos)
            {
                cout << "not found" << endl;
                break;
            }
            else
            {
                std::string tem = _require.substr(0, pos);
                _respon_arr.push_back(tem);
                _require.erase(_require.begin(), _require.begin() + pos + 1);
            }
        }
    }
    void Cutcow(std::string &val)
    {
        int x;
        int y;
        const char *op;
        for (auto &opp : _respon_arr)
        {
            int pos = opp.find(" ");
            x = atoi(opp.substr(0, pos).c_str());
            opp.erase(opp.begin(), opp.begin() + pos + 1);
            pos = opp.find(" ");
            op = opp.substr(0, pos).c_str();
            opp.erase(opp.begin(), opp.begin() + pos + 1);
            y = atoi(opp.c_str());
            switch (*op)
            {
            case '+':
                _respon = std::to_string(x + y);
                break;
            case '-':
                _respon = std::to_string(x - y);
                break;
            case '*':
                _respon = std::to_string(x * y);
                break;
            case '/':
                if (y == 0)
                {
                    cout << "除0错误" << endl;
                    exit(9);
                }
                _respon = std::to_string(x / y);
                break;
            default:
                cout << "不支持此类计算" << endl;
                break;
            }
        }
        val = _respon;
    }

private:
    std::string _require;
    std::string _respon;
    std::vector<std::string> _respon_arr;
};